﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using RescueApp.Models;
using System.IO;

namespace RescueApp.Data
{
    public class RescueContext : DbContext
    {
        public DbSet<RescueApply> RescueApplies { get; set; }
        public DbSet<RescueDispatch> RescueDispatches { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .Build();

            string connectionString = config.GetConnectionString("DefaultConnection");
            optionsBuilder.UseSqlServer(connectionString);
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfiguration(new RescueApplyConfig());
            modelBuilder.ApplyConfiguration(new RescueDispatchConfig());
        }
    }
}